# -*- coding: utf-8 -*-
# @Time : 2024/3/4 21:52
# @Author : TH
# Description:完成响应结果的写入操作

from common.Get_Log import logger
from common.OperationExcelSheet import OperationExcel
from config.readConfig import ReadConfig
from response.Expect_Actual_Compare import ExpectActualCompare


class WriteResponse(ExpectActualCompare):
    def __init__(self):
        # 获取当前excel的workbook对象
        self.excel = OperationExcel()
        # 获取配置文件对象
        self.cf = ReadConfig()

    def write_actual(self, sheet_name, row, expect_value, actual_value, flag):
        """
        获取测试用例实际结果单元格对象并写入数据
        :param sheet_name: excel的sheet名称
        :param row: 当前行
        :param expect_value: 预期结果
        :param actual_value: 实际结果
        :return:返回用例执行情况
        """
        # 获取预期结果与实际结果对比之后的数据
        __get_result = self.expect_actual_compare(expect_value, actual_value, flag)
        logger.info("用例执行结果：%s" % (__get_result))
        # 获取excel中是否通过列
        pass_cell = self.cf.read_ini("EXCEL", "CASE_ISPASS")
        if __get_result == "预期结果与实际结果一致":
            self.excel.write_data(sheet_name, pass_cell, row, "通过")
        else:
            self.excel.write_data(sheet_name, pass_cell, row, "未通过")

        # 在实际结果列写入数据
        actual_cell = self.cf.read_ini("EXCEL", "CASE_ACTUAL")
        self.excel.write_data(sheet_name, actual_cell, row, __get_result)
        return __get_result
